package handler

import (
	"audio-podcast/api/request"
	"audio-podcast/internal/dao"
	"audio-podcast/internal/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddPodcast(c *gin.Context) {
	var req request.AddPodcastForm
	var podcast model.Podcast

	if err := c.ShouldBind(&req); err != nil {
		return
	}

	if req.UserId == 0 || req.Info == "" || req.Name == "" || req.Image == "" {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	podcast = model.Podcast{
		UserId: req.UserId,
		Name:   req.Name,
		Info:   req.Info,
		Image:  req.Image,
	}

	err := dao.AddFile(&podcast)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"msg":  "添加失败",
			"data": nil,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "添加成功",
		"data": nil,
	})
}
